package com.travelDevelop.iterceptor;

import java.util.Map;

import org.springframework.http.server.ServerHttpRequest;
import org.springframework.http.server.ServerHttpResponse;
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.server.support.HttpSessionHandshakeInterceptor;

public class HandshakeInterceptor extends HttpSessionHandshakeInterceptor {

	@Override
	public boolean beforeHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler,
			Map<String, Object> attributes) throws Exception {
		
//		 ServletServerHttpRequest serverHttpRequest = (ServletServerHttpRequest) request;
//         HttpSession session = serverHttpRequest.getServletRequest().getSession();
//         Map parameterMap = serverHttpRequest.getServletRequest().getParameterMap();
//         System.out.println(parameterMap);
//         if (session != null) {
//        	 attributes.put(WebConst.SESSION_LOGIN_USER, session.getAttribute(WebConst.SESSION_LOGIN_USER));
//         }
//		
		// 解决The extension [x-webkit-deflate-frame] is not supported问题
		if (request.getHeaders().containsKey("Sec-WebSocket-Extensions")) {
			request.getHeaders().set("Sec-WebSocket-Extensions", "permessage-deflate");
		}
		return super.beforeHandshake(request, response, wsHandler, attributes);
	}

	@Override
	public void afterHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler,Exception ex) {
		super.afterHandshake(request, response, wsHandler, ex);
	}
}
